package com.example.warehouse.sys.dao.persist.respository.impl;

import com.example.warehouse.common.pojo.vo.PageData;
import com.example.warehouse.common.util.PageInfoToPageDataConverter;
import com.example.warehouse.sys.dao.persist.mapper.SysLogInfoMapper;
import com.example.warehouse.sys.dao.persist.respository.ISysLogInFoRepository;
import com.example.warehouse.sys.pojo.entity.SysLogInfo;
import com.example.warehouse.sys.pojo.vo.SysLogInFoListVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author 欧胤
 * @version 1.0
 * @description: TODO
 * @date 2023/7/14 19:48
 */
@Slf4j
@Repository
public class SysLogInFoRepositoryImpl implements ISysLogInFoRepository {
    @Autowired
    private SysLogInfoMapper mapper;

    @Override
    public int insert(SysLogInfo sysLogInfo) {
        return mapper.insert(sysLogInfo);
    }

    @Override
    public PageData<SysLogInFoListVO> list(Integer pageNum, Integer pageSize) {
        log.debug("开始处理【查询登录日志列表】的业务，页码{},每页记录数{}",pageNum,pageSize);
        PageHelper.startPage(pageNum,pageSize);
        List<SysLogInFoListVO> list = mapper.list();
        PageInfo<SysLogInFoListVO> pageInfo = new PageInfo<>(list);
        return PageInfoToPageDataConverter.convert(pageInfo);
    }

    @Override
    public int deleteById(Long id) {
        log.debug("开始根据id删除登录日志数据, 参数: {}",id);
        return mapper.deleteById(id);
    }
}
